<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="/WEB-INF/tld/app.tld" %>
<%@ taglib prefix="ct" uri="/WEB-INF/tld/commonTag.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/jsp/common/common_header.jsp" %>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>


	<script language="javascript">

	var clickDulId =false;
	var checkRightCd = '';
	$(document).ready(function(){
		var email  = "${model.email}";
		var editType  = "${editType}";
		checkRightCd = $('input[type=radio][name=rightCd]:checked').val();
		
		
		if(checkRightCd == '01'){
			 $("#basicInfo").hide();
			 $("#storeCode").attr('disabled','disabled');
			 $("#vanUserId").attr('disabled','disabled');
			 $("#vanPassword").attr('disabled','disabled');		
			 $("#rightCdFlag").val("01");
		}else{
			 $("#rightCdFlag").val("02");
		}
		//
		
		
		$('#rightCd01').click(function(){
			 $("#basicInfo").hide();
			 $("#storeCode").attr('disabled','disabled');
			 $("#vanUserId").attr('disabled','disabled');
			 $("#vanPassword").attr('disabled','disabled');
			 $("#rightCdFlag").val("01");
			 checkRightCd = "01"
		});		
		
		$('#rightCd02').click(function(){
			 $("#basicInfo").show();
			 $("#storeCode").attr('disabled','');
			 $("#vanUserId").attr('disabled','');
			 $("#vanPassword").attr('disabled','');
			 $("#rightCdFlag").val("02");
			 checkRightCd = "02"
		});		
		
		
		if(editType =="U"){
			clickDulId = true;

			var valFront;
			var valLast;
			if (email.match("@")) {
				valFront = email.substring(0, email.indexOf("@"));
				valLast = email.substring(email.indexOf("@")+1,email.length);
			}
			 $("#emailAddress").val(valFront);
 			 $("#hostEmailAaddress").val(valLast);
        	 $("#duplicateButton").hide();
 			 $("#userId").attr("readonly",true);
 			 $("#bizCode").attr("readonly",true);
 			 $("#comNum").attr("readonly",true);
 			 $("#jumin1").attr("readonly",true);
 			 $("#jumin2").attr("readonly",true);
 			 $("#comCeo").attr("readonly",true);
 			 $("input[name='rightCd']").each(function(i){
 				 $(this).attr('disabled','disabled');
 			 });
		}
	});
	
	

	
	function funcPostSearch() {
		width = 830;
		height = 730;
	    x = (screen.width) ? (screen.width-width)/2 : 0;
	    y = (screen.height) ? (screen.height-height)/2 : 0;
	    var popUrl = '../common/postSearch.do';
		window.open(popUrl,'postSearch', 'left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + ',scrollbars=yes,status=yes,menubar=yes');
	}
    
	function func_selectEmailAddr(obj) {
		if(obj.value == "") {
			$("#hostEmailAaddress").attr("readonly",false);
			$("#hostEmailAaddress").val("");
			$("#hostEmailAaddress").focus();   
		}else{
			 $("#hostEmailAaddress").val(obj.value);
			 $("#hostEmailAaddress").attr("readonly",true);
		}

	}    
	function func_duplicateId() {

		var userId = $("#userId").val();

		if(userId == "") {
			alert("아이디를 입력해주세요!");
			$("#userId").focus();
			return;
		}
		
        var url = "ajaxCheckDuplicateId.do";   

        $.ajax({
            type : "POST",
            url : url,
            async : true,
            dataType : "json",
            data : {
            	id : userId
            },
            success : function(data) {
            	alert(data.user_id+"는 사용 할수 없습니다.")
            },
            error : function(data) {
                alert("사용가능한 아이디 입니다.");
                clickDulId = true;
                $("#userId").focus();
            }
        });   
	} 
	
	
	function goUrl(url) {
		location.href=url;
	}     
	function funDelete() {
		var strStatus ="정말 삭제하시겠습니까?";
		if (confirm(strStatus)) {
	        var fm  = document.form;
	        fm.action = 'memberDelete.do';
	        fm.submit();
		}			
	}
	
	
    
	function funConfirm() {
		
		
		if(validation()){
			return;
		}	
		
		//사업자번호 체크 확인
// 		if(!js_isBusinessNo($("#bizCode").val())){
// 			return;
// 		}
		
		var email = $("#emailAddress").val()+"@"+$("#hostEmailAaddress").val();
		
		if(isEmail(email)){
			alert("email 정보 확인 부탁드립니다.");
			$("#emailAddress").focus();
			return;
		}
		$("#email").val(email);
		
		var editType =$("#editType").val();
			
		var strStatus ="";
		if(editType =="C"){
			strStatus ="정말 등록하시겠습니까?";	
		}else{
			strStatus ="정말 수정하시겠습니까?";	
		}
		
		if (confirm(strStatus)) {
	        var fm  = document.form;
	        fm.action = 'memberConfirm.do';
	        fm.submit();
		}		
		
	} 

	
	function validation() {

		if(!clickDulId){
			alert("중복ID확인를 바랍니다.");
			$("#userId").focus();
			return true;
		}
		
		if($("#password").val() ==""){
			alert("패스워드를 입력해주세요");
			$("#password").focus();
			return true;
		}
		if($("#repassword").val() ==""){
			alert("패스워드확인를 입력해주세요");
			$("#repassword").focus();
			return true;
		}
		
		if($("#password").val() != $("#repassword").val()){
			alert("패스워드가 일치하지 않습니다.");
			$("#password").focus();
			return true;
		}
		
		if($("#emailAddress").val() ==""){
			alert("이메일 주소를 입력해주세요");
			$("#emailAddress").focus();
			return true;
		}
		
		if($("#hostEmailAaddress").val() ==""){
			alert("이메일 주소를 입력해주세요");
			$("#hostEmailAaddress").focus();
			return true;;
		}		
		
		
		if($("#hostEmailAaddress").val() ==""){
			alert("이메일 주소를 입력해주세요");
			$("#hostEmailAaddress").focus();
			return true;;
		}				
		
		if(checkRightCd =="02"){ //비관리자 이면 체크 
			
			if($("#storeName").val() ==""){
				alert("가맹점명 입력해주세요");
				$("#storeName").focus();
				return true;;
			}
			
			if($("#bizCode").val() ==""){
				alert("사업자등록번호를 입력해주세요");
				$("#bizCode").focus();
				return true;;
			}

			if($("#jumin1").val() ==""){
				alert("주민번호 앞자리를 입력해주세요");
				$("#jumin1").focus();
				return true;;
			}		
			
			if($("#jumin2").val() ==""){
				alert("주민번호 뒷자리를 입력해주세요");
				$("#jumin2").focus();
				return true;;
			}
			
			if(!checkSSN($("#jumin1").val()+$("#jumin2").val())){
				alert("잘못된 주민등록번호입니다.\n\n다시 확인하시고 입력해 주세요. ");
				$("#jumin2").focus();
				return true;
			}			

			
			if($("#comCeo").val() ==""){
				alert("대표자명를 입력해주세요");
				$("#comCeo").focus();
				return true;;
			}		
			if($("#postcode").val() ==""){
				alert("우편번호를 검색해주세요");
				$("#postcode").focus();
				return true;;
			}				
	
			if($("#comPhoneNum").val() ==""){
				alert("사업장 전화번호를 입력해주세요");
				$("#comPhoneNum").focus();
				return true;;
			}				
	
				
			
			if($("#merchantFee").val() ==""){
				alert("가맹점 수수료를 입력해주세요");
				$("#merchantFee").focus();
				return true;;
			}			
			
			if($("#checkFee").val() ==""){
				alert("계산서발행 수수료를 입력해주세요");
				$("#checkFee").focus();
				return true;;
			}
	
			if($("#payBankAccount").val() ==""){
				alert("지불은행 계좌번호를 입력해주세요");
				$("#payBankAccount").focus();
				return true;;
			}		
			
			if($("#withdrawBankAccount").val() ==""){
				alert("지불은행 계좌번호를 입력해주세요");
				$("#withdrawBankAccount").focus();
				return true;;
			}		
		}
	} 	
	</script>
</head>
<body>
<div class="con_area" style="width: 800px">
<form id="form" name="form" action="" >
<input type="hidden" id="editType" name="editType" value="${editType}"/>
<input type="hidden" id="email" name="email" value=""/>
<input type="hidden" id="rightCdFlag" name="rightCdFlag" value="${model.rightCd}"/>
<br><br>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="left"><h2 class="tit">회원정보</h2></td>
        <td align="right"><span>회원정보 > <b> 회원정보 상세조회  </b></span></td>
    </tr>
</table>
<br>
<br>
<br>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="left"><h2 class="tit">※ 회원정보 </h2></td>
    </tr>
</table>
<br>
    <div style="margin-top:7px"/>
        <table cellpadding="0" cellspacing="0" border="0" class="data_table_01" width="100%">
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊관리자 권한</td>
                <td class="data_02">
	               <input type="radio" name="rightCd" id="rightCd01" value="01" <c:if test="${model.rightCd eq '01'}"> checked</c:if>>&nbsp;관리자
	               <input type="radio" name="rightCd" id="rightCd02" value="02" <c:if test="${model.rightCd eq '02' or empty model.rightCd}"> checked</c:if>>&nbsp;비관리자
                </td>
            </tr>             
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊아이디</td>
                <td class="data_02">
                	<input type="text" id="userId" name="userId" value="${model.userId}"  size="40"/>
                	&nbsp;&nbsp;
                	<input type="button" class="button_63_01" id="duplicateButton" value="중복 ID확인" style="width:100px; align=center" onclick="func_duplicateId();"/>
                </td>
            </tr>        
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊사용자명</td>
                <td class="data_02">
                	<input type="text" id="userName" name="userName" value="${model.userName}"  size="40"/>
                </td>
            </tr>               
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊비밀번호</td>
                <td class="data_02"><input type="text" id="password" name="password" value="${model.password}"  size="40"/> 
                </td>
            </tr>
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊비밀번호 확인</td> 
                <td class="data_02"><input type="text" id="repassword" name="repassword" value="${model.password}"  size="40"/><font color ="red"> &nbsp;※ 비밀번호를 동일하게 재입력하여 주십시오.</font>
                </td>
            </tr>        
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊이메일 주소</td>
                <td class="data_02">
                		<input type="text" id="emailAddress" name="emailAddress" value=""  size="15"/>
                		&nbsp;@&nbsp;
                		<input type="text" id="hostEmailAaddress" name="hostEmailAaddress" value=""  size="15"/>
	                    <select id="selectEmailAddress" name='selectEmailAddress' onchange="func_selectEmailAddr(this)">
	                    	<option value=''>직접입력</option>
	                        <option value='hanmail.net'>hanmail.net</option>
	                        <option value='naver.com'>naver.com</option>
	                        <option value='nate.com'>nate.com</option>
	                        <option value='korea.com'>korea.com</option>
	                        <option value='yahoo.co.kr'>yahoo.co.kr</option>
	                        <option value='empas.com'>empas.com</option>
	                        <option value='hotmail.com'>hotmail.com</option>
	                    </select>                		
                </td>
            </tr>  
          
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊store 코드</td>
                <td class="data_02"><input type="text" id="storeCode" name="storeCode" value="${model.storeCode}"  disabled size="40"/>
                </td>
            </tr>                
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊VAN사 ID</td>
                <td class="data_02"><input type="text" id="vanUserId" name="vanUserId" value="${model.vanUserId}"  size="40"/>
                </td>
            </tr>        
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊VAN사 비밀번호</td>
                <td class="data_02"><input type="text" id="vanPassword" name="vanPassword" value="${model.vanPassword}"  size="40"/> 
                </td>
            </tr>            
        </table>        
	
<br>
	<div id ="basicInfo">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
		    <tr>
		        <td align="left"><h2 class="tit">※ 기본정보 </h2></td>
		    </tr>
		</table>
		<br>

        <table cellpadding="0" cellspacing="0" border="0" class="data_table_01" width="100%">
            <tr>
                <td class="data_01" style='width:380px; text-align:left;'>&nbsp;＊가맹점명</td>
                <td class="data_02" ><input type="text" id="storeName" name="storeName" value="${model.storeName}"  size="30"/></td>
                <td class="data_01" style='width:380px; text-align:left;'>&nbsp;＊사업자등록번호</td>
                <td class="data_02" ><input type="text" id="bizCode" name="bizCode" value="${model.bizCode}"  size="20" onBlur = "js_CheckTel(this)"/></td>
            </tr>        
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊주민번호</td>
                <td class="data_02"  colspan="3">
                		<input type="text" id="jumin1" name="jumin1" value="${model.jumin1}"  size="20" maxlength ="6" onBlur="js_CheckTel(this)"/>
                		<input type="text" id="jumin2" name="jumin2" value="${model.jumin2}"  size="20" maxlength ="7" onBlur="js_CheckTel(this)"/>
                </td>
             </tr>            
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊법인번호</td>
                <td class="data_02"  colspan="3"><input type="text" id="comNum" name="comNum" value="${model.comNum}"  size="20" onBlur = "js_CheckTel(this)"/></td>
             </tr>
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊대표자명(한글)</td>
                <td class="data_02" ><input type="text" id="comCeo" name="comCeo" value="${model.comCeo}"  size="20"/></td>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊대표자 핸드폰번호</td>
                <td class="data_02" ><input type="text" id="comCeoPhoneNum" name="comCeoPhoneNum" value="${model.comCeoPhoneNum}"  size="20" onBlur = "js_CheckTel(this)"/></td>
            </tr>            
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊서비스</td>
                <td class="data_02" ><input type="text" id="service" name="service" value="${model.service}"  size="20"/></td>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊업종</td>
                <td class="data_02" ><input type="text" id="classification" name="classification" value="${model.classification}"  size="20"/></td>
            </tr>            
          <tr>
                <td class="data_01" style='width:300px; text-align:left;' rowspan ="3">&nbsp;＊사업장 주소</td>
                <td class="data_02" colspan="3">
                		<input type="text" id="postcode" name="postcode" value="${model.postcode}"  size="15" readonly/>
                		<input type="button" class="button_100_01" value="우편번호검색" style="width:100px; align=center" onclick="funcPostSearch()"/>
                </td>
            </tr>
            <tr>
                <td class="data_02" colspan="3">
                		<input type="text" id="jibun_address" name="jibun_address" value="${model.jibun_address}"  size="40" readonly/>
                </td>
			</tr>
            <tr>
                <td class="data_02" colspan="3">
                		<input type="text" id="jibun_details" name="jibun_details" value="${model.jibun_details}"  size="40"/>
                </td>
			</tr>    
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊사업장 전화번호</td>
                <td class="data_02" ><input type="text" id="comPhoneNum" name="comPhoneNum" value="${model.comPhoneNum}"  size="20" onBlur = "js_CheckTel(this)"/></td>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊사업장 팩스번호 </td>
                <td class="data_02" ><input type="text" id="comFaxNum" name="comFaxNum" value="${model.comFaxNum}"  size="20" onBlur = "js_CheckTel(this)"/></td>
            </tr>            
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊업종 상세내역</td>
                <td class="data_02" colspan="3"><input type="text" id="comDetailDesc" name="comDetailDesc" value="${model.comDetailDesc}"  size="55"/></td>
            </tr>  
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊입금 내역 계좌<br>&nbsp;&nbsp;(BC 카드 제외 모든 카드)</td>
                <td class="data_02" colspan="3"><input type="text" id="exceptBcNumber" name="exceptBcNumber" value="${model.exceptBcNumber}"  size="30"/></td>
            </tr>
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊입금 내역 계좌<br>&nbsp;&nbsp;(BC 카드 1)</td>
                <td class="data_02" colspan="3"><input type="text" id="bcNumberFirst" name="bcNumberFirst" value="${model.bcNumberFirst}"  size="30"/></td>
            </tr>  
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊입금 내역 계좌<br>&nbsp;&nbsp;(BC 카드 2)</td>
                <td class="data_02" colspan="3"><input type="text" id="bcNumberSecond" name="bcNumberSecond" value="${model.bcNumberSecond}"  size="30"/></td>
            </tr>                                                                            
        </table>   
        <br>
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
		    <tr>
		        <td align="left"><h2 class="tit">※ 금융정보 </h2></td>
		    </tr>
		</table>
		<br>

        <table cellpadding="0" cellspacing="0" border="0" class="data_table_01" width="100%">
            <tr>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊가맹점수수료</td>
                <td class="data_02" ><input type="text" id="merchantFee" name="merchantFee" value="${model.merchantFee}"  size="10"  onBlur = "js_CheckTel(this)"/>&nbsp; %</td>
                <td class="data_01" style='width:300px; text-align:left;'>&nbsp;＊계산서발행수수료</td>
                <td class="data_02" ><input type="text" id="checkFee" name="checkFee" value="${model.checkFee}"  size="10"  onBlur = "js_CheckTel(this)"/>&nbsp; %</td>
            </tr>        
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊지불은행</td>
                <td class="data_02" colspan="3">
                    <select id="payBank" name='payBank'>
		                    <c:if test='${not empty commonCodeList}'>
		                    	<c:forEach var="code" items="${commonCodeList}">
		                        	<option value=${code.dtl_cd} <c:out value="${model.payBankCd eq code.dtl_cd ? 'selected':''}"/>>${code.cd_nm}</option>
		                        </c:forEach>
		                    </c:if>
                    </select>                    
                	 계좌번호 : <input type="text" id="payBankAccount" name="payBankAccount" value="${model.payBankAccount}"  onBlur = "js_CheckTel(this)"  size="20"/>
                </td>
            </tr>
            <tr>
                <td class="data_01" style='width:250px; text-align:left;'>&nbsp;＊회수은행</td>
                <td class="data_02" colspan="3">
                    <select id="withdrawBank" name=withdrawBank>
		                    <c:if test='${not empty commonCodeList}'>
		                    	<c:forEach var="code" items="${commonCodeList}">
		                        	<option value=${code.dtl_cd} <c:out value="${model.withdrawBankCd eq code.dtl_cd ? 'selected':''}"/>>${code.cd_nm}</option>
		                        </c:forEach>
		                    </c:if>
                    </select>                    
                	계좌번호 : <input type="text" id="withdrawBankAccount" name="withdrawBankAccount" value="${model.withdrawBankAccount}"  onBlur = "js_CheckTel(this)" size="20"/>
                </td>
            </tr>
        </table>    
    </div>       
</form>
</div>
<br><br>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="center">
	        <c:if test='${editType eq "C"}'>
	       		 <input type="button" class="button_63_01" value="등록" style="width:65px; align=center" onclick="funConfirm();"/>
	        </c:if>
			<c:if test='${editType eq "U"}'>
	      		  <input type="button" class="button_63_01" value="수정" style="width:65px; align=center" onclick="funConfirm();"/>
	      		  <input type="button" class="button_63_01" value="삭제" style="width:65px; align=center" onclick="funDelete();"/>
	        </c:if>        
	        <input type="button" class="button_63_01" value="목록" style="width:65px; align=center" onclick="goUrl('memberList.do?pageNo=1')"/>
        </td>
    </tr>
</table>
<br>
<br>
<br>
 
</body>
